Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use npm instead of yarn to build Theia #14481

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

tsmaeder
Copy link
Contributor

What it does

This PR rewrites the Theia build process to use npm in stead of yarn. This required a couple of changes:

Contrary to yarn, npm does not invoke the prepare scripts of workspace packages in the order of their dependencies (npm/cli#3034). So instead of relying on yarn install to invoke the necessary build scripts, we have to invoke the build process explicitly after the npm install. The build process is built on this logic:

  1. Each package has a script called "build". The goal of that target is to fully build all artifacts this repo produces. For regular Theia packages, this is just incrementally compiling the typescript sources of the package an it's dependencies, but for applications, for example, it means creating the application bundle. So calling "build" in an application package should be all that's needed in regular development
  2. To build the repo initially after check-out, there are a couple of additinal steps necesary:
    • compile build tools (re-exports package)
    • generate re-exports where applicable
    • compile all packages
    • build alll application packages
      This can be achieved by invoking npm run build in the repo root.

What's missing:

  • Doc is not up to date
  • linting is currently broken

Fixes #13948

Contributed on behalf of STMicroelectronics

How to test

Make sure we can build Theia as described above and the apps work fine.

Follow-ups

Review checklist

Reminder for reviewers

Fixes eclipse-theia#13948

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
Signed-off-by: Thomas Mäder <[email protected]>
@dankeboy36
Copy link
Contributor

Fixes #13948

Possible related: #775

Signed-off-by: Thomas Mäder <[email protected]>
@tsmaeder
Copy link
Contributor Author

@msujew @sdirix the PR checks now pass and it's ready to be reviewed minus doc.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far it works very well.

I used npm ci to install. I tested all applications and was able to build and start all of them. I also tested watching for the browser application. Tests also completed successfully.

Linting is currently broken but this is already mentioned in the current PR description.

@theia/request: > @theia/[email protected] lint
@theia/request: > theiaext lint
@theia/request: $ eslint --cache=true --no-error-on-unmatched-pattern=true "{src,test}/**/*.{ts,tsx}"
@theia/request: /bin/sh: 1: node: not found
@theia/request: Oops! Something went wrong! :(
@theia/request: ESLint: 8.57.1
@theia/request: SyntaxError: Failed to load plugin '@theia' declared in '.eslintrc.js » ../../configs/build.eslintrc.json » ./base.eslintrc.json': Unexpected end of JSON input
@theia/request:     at JSON.parse (<anonymous>)
@theia/request:     at PackageReExports.FromPackageSync (/home/user/git/theia/dev-packages/private-re-exports/lib/package-re-exports.js:127:47)
@theia/request:     at Object.<anonymous> (/home/user/git/theia/dev-packages/private-eslint-plugin/rules/shared-dependencies.js:24:40)

@@ -1,7 +1,6 @@
root = true

[*]
insert_final_newline = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this? Why remove it?

yarn global add node-gyp
yarn --skip-integrity-check --network-timeout 100000
npm install -g node-gyp
npm install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use npm ci instead of npm install in all workflows to have a more deterministic pipeline. Using ci will not update any dependencies and install them exactly as they are contained in the package-lock.json

Comment on lines +24 to +31
await this.write(this.genConfigPath, this.compileWebpackConfig());
if (!this.pck.isBrowserOnly()) {
await this.write(this.genNodeConfigPath, this.compileNodeWebpackConfig());
}
if (await this.shouldGenerateUserWebpackConfig()) {
await this.write(this.configPath, this.compileUserWebpackConfig());
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like accidental changes

@@ -23,4 +22,4 @@
"ext:test:watch": "mocha -w --config ../../configs/mocharc.yml \"./lib/**/*.*spec.js\"",
"ext:test:clean": "rimraf .nyc_output coverage"
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the newline. I guess this change comes in via the changed .editorconfig.

@@ -117,4 +115,4 @@
"ms-vscode.references-view",
"ms-python.vscode-pylance"
]
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with the newline

"preinstall": "node-gyp install",
"postinstall": "theia-patch",
"prepare": "yarn -s compile:references && lerna run prepare && yarn -s compile",
"postinstall": "theia-patch && npm run -s compute-references && lerna run afterInstall",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference

I would add the compile step here. I don't think there are many use cases where someone wants to run install but not also compile all Typescript files.

Suggested change
"postinstall": "theia-patch && npm run -s compute-references && lerna run afterInstall",
"postinstall": "theia-patch && npm run -s compute-references && lerna run afterInstall && npm run compile",

"performance:startup:electron": "yarn -s electron rebuild && cd scripts/performance && node electron-performance.js --name 'Electron Frontend Startup' --folder electron --runs 10",
"performance:startup": "npm run -s performance:startup:browser && npm run -s performance:startup:electron",
"performance:startup:browser": "concurrently --success first -k -r \"cd scripts/performance && node browser-performance.js --name 'Browser Frontend Startup' --folder browser --runs 10\" \"npm run -s --cwd examples/browser start\"",
"performance:startup:electron": "npm run -s electron rebuild && cd scripts/performance && node electron-performance.js --name 'Electron Frontend Startup' --folder electron --runs 10",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to also have the watch scripts here, e.g. watch, watch:browser etc.

"publish:check": "node scripts/check-publish.js",
"rebuild:clean": "rimraf .browser_modules",
"test": "yarn -s test:theia && yarn -s electron test && yarn -s browser test",
"rebuild:browser": "cd examples/browser && npm run rebuild",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we offer rebuild:browser we should also offer rebuild:electron

"ts-clean": "theia-ts-clean.js"
"run": "bin/theia-run.js",
"theiaext": "bin/theia-ext.js",
"ts-clean-dangling": "bin/theia-ts-clean.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this rename 👍

"publish:check": "node scripts/check-publish.js",
"rebuild:clean": "rimraf .browser_modules",
"test": "yarn -s test:theia && yarn -s electron test && yarn -s browser test",
"rebuild:browser": "cd examples/browser && npm run rebuild",
"start:browser": "cd examples/browser && npm run start",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start:browser-only is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on reviewers
Development

Successfully merging this pull request may close these issues.

Migrate away from yarn v1
3 participants